<template>
  <div class="app-container">
    <div align="left" style="margin-bottom: 10px">
      <el-button type="primary" @click="addData()">新增基金用户</el-button>
    </div>

    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="拼命加载中"
      border
      fit
      highlight-current-row
    >
      <el-table-column align="center" label="序号" width="95">
        <template slot-scope="scope">
          {{ scope.$index }}
        </template>
      </el-table-column>
      <el-table-column label="用户ID" width="200">
        <template slot-scope="scope">
          {{ scope.row.id }}
        </template>
      </el-table-column>
      <el-table-column label="姓名" prop="name" width="150">
        <!--        <template slot-scope="scope">-->
        <!--          {{ scope.row.name }}-->
        <!--        </template>-->
      </el-table-column>
      <el-table-column label="性别" width="100">
        <template slot-scope="scope" prop="sex">
          <span> {{ scope.row.sex===0?'男':'女' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="年龄" width="100">
        <template slot-scope="scope">
          {{ scope.row.age }}
        </template>
      </el-table-column>
      <el-table-column label="手机号" width="180">
        <template slot-scope="scope">
          {{ scope.row.phone }}
        </template>
      </el-table-column>
      <el-table-column label="邮箱" width="180">
        <template slot-scope="scope">
          {{ scope.row.email }}
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="280" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button type="primary" size="mini" @click="editData(scope.row.id)">
            编辑
          </el-button>
          <el-button type="danger" size="mini" @click="delData(scope.row.id)">
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <div align="right">
      <pagination v-show="total>0" align="right" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="fetchData" />
    </div>

  </div>
</template>

<script>
import Pagination from '@/components/Pagination'
import { getList, del } from '@/api/fundUser'

export default {
  components: { Pagination },
  data() {
    return {
      total: 0,
      listQuery: {
        page: 1,
        limit: 10
      },
      list: null,
      listLoading: true
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      var vm = this
      vm.listLoading = true
      getList(this.listQuery.page, this.listQuery.limit).then(response => {
        vm.total = Number(response.data.total)
        vm.list = response.data.records
        vm.listLoading = false
      })
    },
    addData() {
      this.$router.push('/addFundUser/index')
    },
    editData(id) {
      this.$router.push('/editFundUser/index/' + id)
    },
    delData(id) {
      var vm = this
      del(id).then(response => {
        vm.$message.success(response.message)
        vm.fetchData()
      }).catch(function(error) {
        vm.$message.error('删除失败 发生异常' + error)
      })
    }
  }
}
</script>
